const core = require('./lib/core');
const ByteUtil = require('./ByteUtil');
core.start();

// const b = new Buffer.from('EA2700020000400034010001383938363034313631323139383030303431353101000000000000001D55', 'hex');
// function crc16(buffer) {
//   var crc = 0xFFFF;
//   var odd;

//   for (var i = 0; i < buffer.length; i++) {
//       crc = crc ^ buffer[i];

//       for (var j = 0; j < 8; j++) {
//           odd = crc & 0x0001;
//           crc = crc >> 1;
//           if (odd) {
//               crc = crc ^ 0xA001;
//           }
//       }
//   }

//   return crc;
// };

// function reverse (buffer) {
//   for (var i = 0, j = buffer.length - 1; i < j; ++i, --j) {
//     var t = buffer[j]

//     buffer[j] = buffer[i]
//     buffer[i] = t
//   }

//   return buffer
// }
// const reader = new core.BufferReader(b);
// const flag = reader.read(1),
//     length = reader.read(2),
//     version = reader.read(1),
//     equipmentType = reader.read(1),
//     equipmentNumber = reader.read(5),
//     serialNumber = reader.read(2),
//     directive = reader.read(1),
//     data = reader.read(length.readUInt8() - 12),
//     checkSum = reader.read(2);
// const packet = core.concat([flag, length, version, equipmentType, equipmentNumber, serialNumber, directive, data])
// console.log(core.createIntBufferLE(crc16(packet), 2), packet.toString('hex'), checkSum)
// const dataReader = new core.BufferReader(data);
// console.log(dataReader.read(20), dataReader.read(2), dataReader.read(6) );

// const cbuf = new Buffer.from('022ad5caff8042324c33323438300f313818002516000000000000000000010000000000000000000c03', 'hex');
// const pile = {
//   code: ByteUtil.getPileCode(cbuf),
//   cmd: ByteUtil.byteTo16(cbuf[5]),
//   info: ByteUtil.getPileInfo(cbuf),
//   dataIndex: ByteUtil.analysisDataIndex(cbuf, 2),
// };

// let by = Buffer.alloc(90);
// by = ByteUtil.getByteByStx(141, pile.dataIndex, by);
// by = ByteUtil.getByteByPileCodeOrAccountNo(6, pile.code, by);
// by = ByteUtil.getByFee(by, 12, 2);
// by = ByteUtil.getByteByExit(by);
// console.log(by)
